<template>
  <view class="container">
    <FilterNavbar :searchList="searchList" v-model:queryParam="queryParam" @confirm="toList">
      <template #center>
        <view class="navbar-title"> 里程记录 </view>
      </template>
    </FilterNavbar>
    <scroll-view
      scroll-y
      :scroll-top="scrollTop"
      :scroll-with-animation="true"
      refresher-enabled
      :refresher-triggered="refreshStatus"
      :enable-back-to-top="true"
      @refresherrefresh="resetRefresh(true)"
      @scrolltolower="reachBottom"
    >
      <view class="record-list">
        <OrderItem v-for="record in dataSource" :record="record" :key="record.id" />
        <!-- 加载结束列表为空时展示 -->
        <ve-empty v-if="dataSource.length == 0 && loadStatus == 'nomore'"></ve-empty>
        <!-- 底部加载状态 -->
        <ve-load-more v-else :status="loadStatus" bgColor="#F7F7F9"></ve-load-more>
      </view>
    </scroll-view>
  </view>
</template>

<script setup>
  import { ref, computed } from 'vue'
  import { onLoad } from '@dcloudio/uni-app'
  import FilterNavbar from '@/components/FilterNavbar'
  import { usePageDict } from '@/hooks/useDict'
  import useList from '@/hooks/useList'
  import OrderItem from './mileage-record-order-item.vue'

  const dict = usePageDict('carManagerToListDict')

  const searchList = computed(() => {
    return [
      {
        prop: ['updateTimeStart', 'updateTimeEnd'],
        label: '更新时间',
        type: 'daterange-picker',
      },
      {
        prop: 'businessType',
        label: '业务类型',
        type: 'picker',
        attrs: {
          options: dict.businessTypeList,
        },
      },
      {
        prop: 'event',
        label: '更新事件',
        type: 'picker',
        attrs: {
          options: dict.eventList,
        },
      },
    ]
  })

  const queryParam = ref({})

  const { resetRefresh, reachBottom, loadData, scrollTop, loadStatus, refreshStatus, dataSource } = useList(
    '/V5/carInfo/getMileageRecord',
    queryParam,
  )
  const toList = () => {
    dataSource.value = []
    loadData(1)
  }

  onLoad((options) => {
    queryParam.value = {
      id: options.id,
    }
    loadData()
  })
</script>

<style lang="less" scoped>
  .container {
    height: 100vh;
  }
  .record-list {
    padding: 24rpx;
  }
  .navbar-title {
    font-size: 34rpx;
    font-weight: 500;
    color: #1d2129;
  }
</style>
